import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex);
function isArray(o) {
    return Object.prototype.toString.call(o) == '[object Array]';
}
function callAsyncMethod(callback){
  callback()
};
const store = new Vuex.Store({
    plugins: [createPersistedState({
        storage: window.sessionStorage
    })],
    state: {
      showleftTree:true,//控制页面最左边树结构盒子显示隐藏
      stationInfo:[],
      count:0,
      menuIndex:0,//主页面一级导航选中状态
      navTitle:'',//主页面左上角导航小标题
      levmenuIndex:0,//主页面二级导航选中状态
      levMenudata:[],// 主页面二级导航数据
      childMenu:'',//三级导航选中状态
      isChange:'',
      siteMn:'',//站点Mn号
    },
    getters: {
       
    },
    mutations: {
      setSiteMn(state, val){
        state.siteMn = val;
      },
      setisChange(state, val){
        state.isChange = val;
      },
      //设置公共树结构显示隐藏
      setShowlefttree(state, val) {
        state.showleftTree = val;
      },
      setMenuIndex(state, val){
        state.menuIndex = val;
      },
      setNavTitle(state, val){
        state.navTitle = val;
      },
      setLevmenuIndex(state, val){
        state.levmenuIndex = val;
      },
      setLevMenudata(state, val){
        state.levMenudata = val;
      },
      setChildMenu(state, val){
        state.childMenu = val;
      },
      setStationinfo(state, obj){
        //判断传进来的参数是数组还是对象
        if(typeof obj && isNaN(obj.length)){
          state.stationInfo=[];
          state.stationInfo.push(obj);
        }else{
          state.stationInfo = obj;
        };
        sessionStorage.setItem('stationInfo', JSON.stringify(state.stationInfo))
      }
    },
    actions: {

    },
    modules: {

    }
});

export default store
